package jam.objects {
	import org.flixel.FlxPoint;
	import org.flixel.FlxSound;
	import jam.registry.Resource;
	import org.flixel.FlxSprite;

	/**
	 * @author oati
	 */
	public class Checkpoint extends FlxSprite {
		
		private var checkpointSound:FlxSound;
		
		public function Checkpoint(X : Number = 0, Y : Number = 0, SimpleGraphic : Class = null) {
			super(X*Game.TILE_SIZE + 5, Y*Game.TILE_SIZE + 8);
			loadGraphic(Resource.CHECKPOINT, true, false, 15, 28);
    		addAnimation("down", [0, 1, 2, 3, 4, 5], 8, true);
			addAnimation("raise", [6, 7, 8, 9, 10], 8, false);
			addAnimation("up", [11, 12, 13, 14, 15, 16], 8, true);
			addAnimationCallback(handleAnimationChanged);
			this.immovable = true;
			height = 1;
			offset.y = 28;
			play("down");
			
			checkpointSound = new FlxSound();
			checkpointSound.loadEmbedded(Resource.SOUND_SLIDE_WHISTLE);
		}
		
		public function raiseFlag():void {
			checkpointSound.play();
			play("raise");
		}
		
		private function handleAnimationChanged(name:String, frameNumber:uint, frameIndex:uint):void
		{
			if (name == "raise" && this.finished)
			{
				play("up");
			}
		}
	}
}
